Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic storage inspection command #1395

Merged
merged 39 commits into from
Nov 27, 2023
Merged

Basic storage inspection command #1395

merged 39 commits into from
Nov 27, 2023

Conversation

ascjones
Copy link
Collaborator

@ascjones ascjones commented Nov 10, 2023

This provides a foundation for #101.

It queries all the storage entries for a contract, and then associates the entries with root keys from the contract metadata storage layout, printing the results as JSON for now:

image

Also can display the raw storage keys/values if specified or if no contract metadata available:

image

For now the structure of the cells is flat, and only the raw data for the cells is shown. To continue on from this we should:

  • Refine and possible structure the output types (e.g. grouping per root key)
  • Option for displaying non-json user friendly view of data (see Michi's picture in Storage inspection command #101)
  • Decode the raw data using metadata from the contract.

@ascjones ascjones marked this pull request as ready for review November 22, 2023 18:58
@smiasojed
Copy link
Collaborator

I think we should update the CHANGELOG.md and the usage section of README.md file

@ascjones
Copy link
Collaborator Author

I think we should update the CHANGELOG.md and the usage section of README.md file

Done, but only a basic entry in the README, can be updated once the command is more fleshed out.


/// Represents the raw key/value storage for the contract.
#[derive(Serialize)]
pub struct ContractStorageData(BTreeMap<Bytes, Bytes>);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need a dedicated structure for this if it only contains a single field, and has no methods?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't strictly need it, just using the newtype idiom for readability: it is a public API so for me it is nice to have types describing the data. So the BTreeMap I have used internally just because it serializes the key/values nicely into json, but that could change if we want to add more information in there, or have a different layout.

}
}
Layout::Array(_) => {
todo!("Figure out what to do with an array layout")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the context?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The context is that once we merge this pull request, I will continue working on storage inspection command.

crates/extrinsics/src/contract_artifacts.rs Show resolved Hide resolved
@SkymanOne
Copy link
Contributor

Also worth looking at https://docs.rs/csv/latest/csv/cookbook/index.html#writing-basic to display values in CSV format

Copy link
Collaborator

@smiasojed smiasojed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ascjones ascjones merged commit dbfa9ad into master Nov 27, 2023
11 checks passed
@ascjones ascjones deleted the aj/storage-basic branch November 27, 2023 11:01
@smiasojed smiasojed mentioned this pull request Nov 30, 2023
@smiasojed smiasojed mentioned this pull request Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants